package me.zhengjie.modules.lock.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.modules.lock.service.LockDeviceCmdService;
import me.zhengjie.modules.lock.service.vo.LockDeviceCmdListReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(tags = "操作指令：指令列表")
@RequestMapping("/api/v1/lock/cmd")
public class LockDeviceCmdController {
    @Autowired
    private LockDeviceCmdService lockDeviceCmdService;

    @AnonymousAccess
    @ApiOperation("查询操作指令列表")
    @GetMapping(value = "/list")
    //@PreAuthorize("@el.check('cmd:list')")
    public ResponseEntity<Object> getLockCmdList(LockDeviceCmdListReqVO lockDeviceCmdListReqVO, Pageable pageable) {
        return new ResponseEntity<>(lockDeviceCmdService.getLockCmdList(lockDeviceCmdListReqVO, pageable), HttpStatus.OK);
    }

    @AnonymousAccess
    @ApiOperation("查询操作指令请求和响应参数")
    @GetMapping(value = "/perform/info")
    //@PreAuthorize("@el.check('cmd:list')")
    public ResponseEntity<Map<String, String>> getLockCmdPerformInfo(@RequestParam("cmdId") Long cmdId) {
        return new ResponseEntity<>(lockDeviceCmdService.getLockCmdPerformInfo(cmdId), HttpStatus.OK);
    }
}
